# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=gnu-cobol
pkgbase=mingw-w64-${_realname}-svn
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-svn
_base_ver=2.0
pkgver=2.0.r599
pkgrel=2
pkgdesc="GNU Cobol is a free, modern COBOL compiler (mingw-w64)"
arch=('any')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url="https://sourceforge.net/projects/open-cobol/"
options=('strip')
license=('GPL' 'LGPL')
makedepends=("subversion"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libiconv")
depends=("${MINGW_PACKAGE_PREFIX}-db"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-ncurses")
source=("${_realname}::svn+http://svn.code.sf.net/p/open-cobol/code/branches/gnu-cobol-2.0")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  local ver="$(svnversion)"
  printf "%s.r%s" "${_base_ver}" "${ver//[[:alpha:]]}"
}

prepare() {
  cd ${srcdir}/${_realname}
  autoreconf -fi
}

build() {
  export lt_cv_deplibs_check_method='pass_all' # libncurses
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${_realname}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --infodir=${MINGW_PREFIX}/share/info \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static \
    --disable-rpath

  make -j1
}

package() {
  cd ${srcdir}/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp -pf ${srcdir}/${_realname}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
}
